from django.db import models
from django.contrib.auth.models import AbstractUser, Group
from django.utils import timezone

from task_manage_sys.mixins import BaseModelMixin


class Clazz(BaseModelMixin):
    name = models.CharField(max_length=100, db_comment="班级名")

    duration = models.FloatField(db_comment="课程时长")

    manage_name = models.CharField(max_length=100, db_comment="班主任")

    start_time = models.DateField(db_comment="开班时间")

    state = models.BooleanField(db_comment="班级状态", default=False)

    class Meta:
        db_table = 'tb_clazz'


class User(AbstractUser):
    # 维护 和 班级的关系
    clazz = models.ForeignKey(to=Clazz, on_delete=models.CASCADE, blank=True, null=True)

    class Meta(AbstractUser.Meta):
        db_table = "tb_user"
        swappable = "AUTH_USER_MODEL"


class PersonGroup(BaseModelMixin):
    """扩展用户组模型、添加额外的字段到另一张表中"""
    group = models.OneToOneField(to=Group, on_delete=models.CASCADE, blank=True, null=True)
    # 维护和班级的关系
    clazz = models.ForeignKey(to=Clazz, on_delete=models.CASCADE, blank=True, null=True)
    class Meta:
        db_table = "auth_group_status"
